package com.lagou.jdbc02;

import com.lagou.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

public class TestDQL {
    public static void main(String[] args) throws Exception {
        //查询姓名为邵重德的一条记录
        //1.获取连接
        Connection connection= JDBCUtils.getConnection();
        //2.创建Statement对象
        Statement statement=connection.createStatement();

        //3.编写SQL
        String sql="select * from jdbc_user where username='邵重德'";
        ResultSet resultSet=statement.executeQuery(sql);

       //4.处理结果集
       while(resultSet.next()){
           //通过列名的方式获取
           int id = resultSet.getInt("id");
           String str1=resultSet.getString("username");
           String str2=resultSet.getString("password");
           Date birthday=resultSet.getDate("birthday");
           System.out.println(id+","+str1+","+str2+","+birthday);
       }

       //5.释放资源
        JDBCUtils.close(connection,statement,resultSet);
    }
}
